#include "Screen.h"
#include <iostream>
#include <assert.h>
#include "Game.h"

Screen::Screen()
{
	SDL_Init(SDL_INIT_EVERYTHING); // Initialises SDL
	m_Surface = 0;

	////joystick
	//int NumberofJoysticks = SDL_NumJoysticks();
	//for (int i = 0; i < NumberofJoysticks; i++)
	//{
	//	SDL_JoystickOpen(i);
	//}
	//SDL_JoystickEventState(SDL_ENABLE);
}

Screen::~Screen()
{
	SDL_Quit(); // opposite to SDL_Init, deallocates memory and free's up space
}

bool Screen::CreateWindow()
{
	int Width = TheGame::Instance()->ReturnResolutionX();
	int Height = TheGame::Instance()->ReturnResolutionY();
	bool FullScreen = TheGame::Instance()->ReturnFullScreenValue();

	if (FullScreen == true)
	{
		m_Surface = SDL_SetVideoMode(Width, Height, 0, SDL_OPENGL | SDL_FULLSCREEN);
	}
	else
	{
		m_Surface = SDL_SetVideoMode(Width, Height, 0, SDL_OPENGL);
	}

	SDL_WM_SetCaption("OpenGL Engine", NULL);

	//std::string IconPath = "Assets/Textures/Icon.png";
	//SDL_WM_SetIcon(IMG_Load(IconPath.c_str()), NULL);

	return (m_Surface != 0); // returns true or false (0 or 1)
}

void Screen::Flip()
{
	SDL_GL_SwapBuffers();
}

SDL_Surface* Screen::GetSurface()
{
	assert(m_Surface);
	return m_Surface;
}